package com.sixfoot.domain;

import com.sixfoot.domain.scale.Scale;
import com.sixfoot.foundation.persistence.UUIDBaseModel;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

@Entity
@Table(name = "user")
public class User extends UUIDBaseModel {
	private String username;					// 用户名
	private String password;					// 密码
	private Set<Role> roles;					// 拥有的角色
	private Boolean locked = Boolean.FALSE;		// 是否锁定
	private Organization organization;			// 所属组织
	private Set<Scale> scales;					// 记录
	/************************************
	 * 详细信息
	 ************************************/
	private String realName;					// 真实姓名
	private Integer sex;						// 性别
	private Date birthday;						// 生日
	private String mobile;						// 电话
	private Integer height;						// 身高
	private Integer weight;						// 体重
	private String workingPlace;				// 工作单位
	private String position;					// 职务
	private String medicalHistory;				// 既往病史

	public User() {
	}

	public User(String username, String password) {
		this.username = username;
		this.password = password;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Boolean getLocked() {
		return locked;
	}

	public void setLocked(Boolean locked) {
		this.locked = locked;
	}

	@ManyToOne
	@JoinColumn(name = "organization_id")
	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "user_role")
	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	
	@OneToMany(mappedBy = "user")
	public Set<Scale> getScales() {
		return scales;
	}
	
	public void setScales(Set<Scale> scales) {
		this.scales = scales;
	}
	
	@Override
	public String toString() {
		return "User{" + "id=" + super.getId() + ", username='" + username + '\''
				+ ", password='" + password  + '\''
				+ ", locked=" + locked + '}';
	}
	
	@Temporal(TemporalType.DATE)
	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	@Column(length = 1)
	public Integer getSex() {
		return sex;
	}

	public void setSex(Integer sex) {
		this.sex = sex;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	
	@Column(columnDefinition = "tinyint")
	public Integer getHeight() {
		return height;
	}

	public void setHeight(Integer height) {
		this.height = height;
	}

	@Column(columnDefinition = "tinyint")
	public Integer getWeight() {
		return weight;
	}

	public void setWeight(Integer weight) {
		this.weight = weight;
	}

	public String getWorkingPlace() {
		return workingPlace;
	}

	public void setWorkingPlace(String workingPlace) {
		this.workingPlace = workingPlace;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public String getMedicalHistory() {
		return medicalHistory;
	}

	public void setMedicalHistory(String medicalHistory) {
		this.medicalHistory = medicalHistory;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

}
